package com.wechat.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fhMall.request.QueryProductListRequest;
import com.wechat.core.bean.Result;
import com.wechat.feign.FhEmallProductApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 程序名：.java<br>
 * 程序功能 <br>
 * 作成者：xianlin <br>
 * 日期：2019-09-19 20:46<br>
 * 修改履历 <br>
 * 项目名    状态      作成者      日期   <br>
 * --------------------------------------- <br>
 * 新规      xianlin   2019-09-19 20:46 <br>
 * ----------------------------- <br>
 */
@RestController
@RequestMapping("wechat/product")
@Api(tags = "微商城商品")
public class WechatProductController extends BaseController {

    @Autowired
    private FhEmallProductApi fhEmallProductApi;

    /**
     * 微商城商品列表
     * @return 微商城商品列表
     */
    @ApiOperation(value="查询微商城商品列表")
    @GetMapping(value = "/productList")
    public JSONObject queryProductList( @RequestParam(name="categoryId") Integer categoryId,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        String result = fhEmallProductApi.queryProductByCategory(categoryId, pageNo, pageSize);
        return JSONObject.parseObject(result);
    }

    @ApiOperation(value="查询微商城商品列表")
    @GetMapping(value = "/searchProductList")
    public JSONObject searchProductList( @RequestParam(name="keyword") String keyword,
                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        String result = fhEmallProductApi.searchProductList(keyword, pageNo, pageSize);
        return JSONObject.parseObject(result);
    }
    /**
     * 微商城商品详情
     * @param id 商品ID <br>
     * @return 微商城商品详情 <br>
     */
    @ApiOperation(value = "微商城商品详情")
    @GetMapping(value = "/detail")
    public JSONObject details(@RequestParam(value = "id") String id) {
        String result = fhEmallProductApi.queryProductInfo(id);
        return JSONObject.parseObject(result);
    }

    @ApiOperation(value = "下单页面商品查询")
    @GetMapping(value = "/submitProducts")
    public JSONObject submitCheck(@RequestParam("productIds") String productIds){
        System.out.println(productIds+"-----------------------");
        String result = fhEmallProductApi.queryProductsInfo(productIds);
        return JSONObject.parseObject(result);
    }

}
